﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace TCS.Web.MembersHome
{
    public partial class EditAccountInfo : MembersClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!this.IsPostBack)
            {
                BindSuppData();
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    string id = Request.Params["id"];
                    BindData(int.Parse(id));
                }
            }
        }
        private void BindSuppData()
        {
            TCS.BLL.Gsp_Administrative bll = new TCS.BLL.Gsp_Administrative();
            this.dropArea.DataSource = bll.GetAllList();
            this.dropArea.DataTextField = "addName";
            this.dropArea.DataValueField = "addId";
            this.dropArea.DataBind();

            this.dropArea.Items.Insert(0, new ListItem("--请选择--", "-1"));
        }
        private void BindData(int MemberID)
        {
            TCS.BLL.MemberInfo bll = new TCS.BLL.MemberInfo();
            TCS.Model.MemberInfo model = bll.GetModel(MemberID);
            //this.txtCodeName.Text = model.CodeName;
            //txtCodeName.ReadOnly = true;
            ////this.lblPassword.Text = model.Password;
            //ViewState["password"] = model.Password;
            //this.txtEnName.Text = model.EnName;
            //this.txtCreateTime.Text = model.CreateTime;
            ////this.txtAddID.Text = model.AddID.ToString();
            //dropArea.SelectedIndex = -1;
            //dropArea.Items.FindByValue(model.Addid.ToString()).Selected = true;
            //this.txtBisAddr.Text = model.BisAddr;
            //this.txtBisPost.Text = model.BisPost;
            //this.txtWarehouseAddr.Text = model.WarehouseAddr;
            //this.txtWarehousePost.Text = model.WarehousePost;
            //this.txtLegalName.Text = model.LegalName;
            //this.txtLegalTel.Text = model.LegalTel;
            //this.txtLegalAddr.Text = model.LegalAddr;
            //this.txtLegalPost.Text = model.LegalPost;
            //this.txtMgrName.Text = model.MgrName;
            //this.txtMgrTel.Text = model.MgrTel;
            //this.txtMgrEmail.Text = model.MgrEmail;
            //this.txtContactName.Text = model.TrueName;
            //this.txtContactTel.Text = model.ContactTel;
            //this.txtContactEmail.Text = model.TrueName;
            //this.txtIsDelete.Text = model.IsDelete == null || model.IsDelete.ToString() == "0" ? "<font color=green>正常</a>" : "<font color=red>已注销</a>";
             //ViewState["IsDelete"] = model.Isdelete;
            //this.txtAddTime.Text = model.AddTime;
            //this.txtLastLoginTime.Text = model.LastLoginTime;
            //this.txtAboutUs.Text = model.Image;
            //this.txtOrgStructure.Text = model.QQ;
            //this.txtManageSystem.Text ="";
            //this.txtQualification.Text ="";
            //ViewState["AddTime"] = model.AddTime;
            //ViewState["LastLoginTime"] = model.LastLoginTime;
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtCodeName.Text == "")
            {
                strErr += "登录名不能为空！\\n";
            }
            //if (this.txtPassword.Text == "")
            //{
            //    strErr += "密码不能为空！\\n";
            //}
            if (this.txtEnName.Text == "")
            {
                strErr += "企业名称不能为空！\\n";
            }

            if (this.dropArea.SelectedValue == "-1")
            {
                strErr += "请选择行政区域！\\n";
            }

            if (strErr != "")
            {
                LTP.Common.MessageBox.Show(this, strErr);
                return;
            }

            string CodeName = this.txtCodeName.Text;
            string Password = this.txtPassword.Text == "" ? ViewState["password"].ToString() : this.txtPassword.Text;
            string EnName = this.txtEnName.Text;
            int AddID = int.Parse(this.dropArea.SelectedValue);

            string CreateTime = this.txtCreateTime.Text;
            string BisAddr = this.txtBisAddr.Text;
            string BisPost = this.txtBisPost.Text;
            string WarehouseAddr = this.txtWarehouseAddr.Text;
            string WarehousePost = this.txtWarehousePost.Text;
            string LegalName = this.txtLegalName.Text;
            string LegalTel = this.txtLegalTel.Text;
            string LegalAddr = this.txtLegalAddr.Text;
            string LegalPost = this.txtLegalPost.Text;
            string MgrName = this.txtMgrName.Text;
            string MgrTel = this.txtMgrTel.Text;
            string MgrEmail = this.txtMgrEmail.Text;
            string ContactName = this.txtContactName.Text;
            string ContactTel = this.txtContactTel.Text;
            string ContactEmail = this.txtContactEmail.Text;
            int IsDelete = (int)ViewState["IsDelete"];
            string AddTime = ViewState["AddTime"].ToString();
            string LastLoginTime = ViewState["LastLoginTime"].ToString();
            string AboutUs = this.txtAboutUs.Text;
            string OrgStructure = this.txtOrgStructure.Text;
            string ManageSystem = this.txtManageSystem.Text;
            string Qualification = this.txtQualification.Text;

            TCS.Model.MemberInfo model = new TCS.BLL.MemberInfo().GetModel(1);
            //model.MemberID = int.Parse(Request.Params["id"].ToString());
            //model.CodeName = CodeName;
            //model.Password = Password;
            //model.EnName = EnName;
            //model.CreateTime = CreateTime;
            //model.Addid = AddID;
            //model.BisAddr = BisAddr;
            //model.BisPost = BisPost;
            //model.WarehouseAddr = WarehouseAddr;
            //model.WarehousePost = WarehousePost;
            //model.LegalName = LegalName;
            //model.LegalTel = LegalTel;
            //model.LegalAddr = LegalAddr;
            //model.LegalPost = LegalPost;
            //model.MgrName = MgrName;
            //model.MgrTel = MgrTel;
            //model.MgrEmail = MgrEmail;
            //model.TrueName = ContactName;
            //model.ContactTel = ContactTel;
            //model.Email = ContactEmail;
            //model.Isdelete = IsDelete;
            //model.AddTime = AddTime;
            //model.LastLoginTime = LastLoginTime;
            //model.Image = AboutUs;
            //model.QQ = OrgStructure;

           TCS.BLL.MemberInfo bll = new TCS.BLL.MemberInfo();
            bll.Update(model);
            //if (chkAddContinue.Checked)
            //{
            //    Response.Redirect("index.aspx");
            //}
            //else
            //{
            //    Response.Redirect("index.aspx");
            //}
            LTP.Common.MessageBox.Show(Page,"保存成功!");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            //this.Response.Redirect("index.aspx");
        }
    }
}

